package cn.yougou.serviceImpl;

import cn.yougou.common.DateUtil;
import cn.yougou.mapper.YgStorageMapper;
import cn.yougou.pojo.YgStorage;
import cn.yougou.service.YgStorageService;
import cn.yougou.vo.YgStorageVo;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class YgAdminStorageImpl implements YgStorageService {

    @Autowired
    private YgStorageMapper ygStorageMapper;

    /**
     * 图片对象信息插入，获取自增id
     * @param ygStorage
     * @return
     */
    @Override
    public YgStorageVo insert(YgStorage ygStorage) {
        ygStorageMapper.insert(ygStorage);
        YgStorageVo ygStorageVo = new YgStorageVo(
                ygStorage.getId(), //获取到插入的自增id
                ygStorage.getName(),
                ygStorage.getSize(),
                ygStorage.getType(),
                ygStorage.getUrl(),
                DateUtil.getSdf(ygStorage.getAddTime()),
                ygStorage.getUpdateTime()!=null? DateUtil.getSdf(ygStorage.getUpdateTime()):null
        );
        return ygStorageVo;
    }

    /**
     * 根据id删除数据库记录
     * @param id
     * @return
     */
    @Override
    public int deleteById(Integer id) {
        return ygStorageMapper.deleteById(id);
    }

}
